# -*- coding: utf-8 -*-

"""
"""
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework.pagination import LimitOffsetPagination
from collections import OrderedDict
from rest_framework import status


class CustomPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 999

    def get_paginated_response(self, data: list):
        msg = "获取成功"
        if not data:
            msg = "No Data"

        result = OrderedDict([
            ('code', status.HTTP_200_OK),
            ('message', msg),
            ('success', True),
            ('count', self.page.paginator.count),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('results', data),
        ])

        return Response(result)

    @staticmethod
    def get_no_paginated_response(data: list):
        msg = "获取成功"
        if not data:
            msg = "No Data"

        result = OrderedDict([
            ('code', status.HTTP_200_OK),
            ('msg', msg),
            ('success', True),
            ('count', len(data)),
            ('next', None),
            ('previous', None),
            ('results', data),
        ])

        return Response(result)


